package com.kayt.cyberBar.cuser.business.dao.impl;

import java.sql.SQLException;
import java.util.LinkedHashMap;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.kayt.cyberBar.common.PageData;
import com.kayt.cyberBar.common.dao.EntityDao;
import com.kayt.cyberBar.cuser.business.dao.ISheetUserWorkDao;
import com.kayt.cyberBar.cuser.business.entity.po.BSheetUserWork;

@Repository("sheetUserWorkDao")
public class SheetUserWorkDaoImpl implements ISheetUserWorkDao {
	@Autowired
	private EntityDao entityDao;
	
	@Override
	public Integer save(BSheetUserWork entity) throws SQLException {
			if(entity != null){
				entityDao.save(entity);
				return 0;
			}else{
				return -1;
			}
	}

	@Override
	public Integer update(BSheetUserWork entity) throws SQLException {
		
			if(entity != null){
				entityDao.update(entity);
				return 0;
			}else{
				return -1;
			}
	}

	@Override
	public Integer delete(Integer id) {
		
			if(id != null){
				BSheetUserWork BSheetUserWork = findById(id);
				if(BSheetUserWork != null){
					entityDao.delete(BSheetUserWork);
					return 0;
				}else{
					return -1;
				}
			}else{
				return -1;
			}
	}

	@Override
	public BSheetUserWork findById(Integer id) {
		
			if(id != null){
				return entityDao.findById(id, BSheetUserWork.class);
			}else{
				return null;
			}
	}

	@Override
	public PageData<BSheetUserWork> findByPage(int pageNum, int pageSize, String hql, Object[] params,
			LinkedHashMap<String, String> orderMap) throws SQLException {
		return this.entityDao.getPagingData(BSheetUserWork.class, pageNum, pageSize, hql, params, orderMap);
	}

	@Override
	public BSheetUserWork findByUserCode(String userCode) throws SQLException {
		return entityDao.getObj(BSheetUserWork.class, "o.userCode = ?", new Object[]{userCode});
	}

}
